package seismosurfer.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.help.HelpBroker;

import com.bbn.openmap.MapBean;
import com.bbn.openmap.gui.ToolPanel;

/**
 * A <a href="http://www.martinfowler.com/eaaCatalog/registry.html">Registry</a>
 * implementation for the applet.
 *
 */
public class ClientRegistry {

    public static final String HELPBROKER = "helpbroker";

    public static final String TOOLPANEL = "toolpanel";

    public static final String MAPBEAN = "maphandler";

    private static ClientRegistry instance = new ClientRegistry();

    private Map registry = new HashMap();

    protected ClientRegistry() {
    }
    
    /**
     * Gets the properties of the application
     * as a Properties object.
     * 
     * @return a Properties object
     */
    public static Properties getOpenmapProperties() {
        return (Properties) instance.registry.get(Registry.PROPERTIES);
    }
    
    /**
     * Stores the properties of the application.
     * 
     * @param p the Properties object to be stored
     */
    public static void setOpenmapProperties(Properties p) {
        Assert.notNull(p);
        instance.registry.put(Registry.PROPERTIES, p);
    }
    
    /**
     * Stores a HelpBroker object which is
     * used for the online help.
     * 
     * @param hb the HelpBroker to be stored
     */
    public static void setHelpBroker(HelpBroker hb) {
        Assert.notNull(hb);
        instance.registry.put(HELPBROKER, hb);
    }
    
    /**
     * Gets the ToolPanel component which is 
     * used to hold the tools.
     * 
     * @return a ToolPanel object
     */
    public static ToolPanel getToolPanel() {
        return (ToolPanel) instance.registry.get(TOOLPANEL);
    }
    
    /**
     * Stores the ToolPanel component.
     * 
     * @param tp the ToolPanel object
     */
    public static void setToolPanel(ToolPanel tp) {
        Assert.notNull(tp);
        instance.registry.put(TOOLPANEL, tp);
    }
    
    /**
     * Provides access to the MapBean.
     * 
     * @return the MapBean object
     */
    public static MapBean getMapBean() {
        return (MapBean) instance.registry.get(MAPBEAN);
    }
    
    /**
     * Stores a reference to the MapBean.
     * 
     * @param mb the MapBean object
     */
    public static void setMapBean(MapBean mb) {
        Assert.notNull(mb);
        instance.registry.put(MAPBEAN, mb);
    }
    
    /**
     * Gives access to a HelpBroker object which is
     * used for the online help.
     * 
     * @return a HelpBroker object
     */
    public static HelpBroker getHelpBroker() {
        return (HelpBroker) instance.registry.get(HELPBROKER);
    }

}